{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<a href="{% url 'add' %}">
    <button>添加</button>
</a>
<button onclick="on()">批量删除</button>
<table border="1">
    <tr>
        <td>
            {#                        <button onclick="al()">全选</button>#}
            <input type="checkbox" id="aa" >
        </td>
        <td>编号</td>
        <td>标题</td>
        <td>内容</td>
        <td>状态</td>
        <td>时间</td>
        <td>添加人</td>
    </tr>
    <tbody id="aaa">
    {% for foo in cont %}
        <tr>
            <td><input type="checkbox" name="chee" value="{{ foo.id }}"></td>
            <td>{{ forloop.counter }}</td>
            <td>{{ foo.tits }}</td>
            <td>{{ foo.content }}</td>
            <td>{% if foo.zt == 1 %}
                通过
            {% else %}
                未通过
            {% endif %} </td>
            <td>{{ foo.time|date:'Y-m-d' }}</td>
            <td>{{ foo.name.username }}</td>
            <td><a href="{% url 'delete' cid=foo.id %}">删除</a></td>
            <td><a href="{% url 'update' cid=foo.id %}">修改</a></td>


        </tr>
    {% endfor %}
    </tbody>


</table>
<script src="{% static 'js/jquery-3.4.1.min.js' %}"></script>
<script>
    {#alert("换迎{{ request.session.user }}登录")#}

    $(function () {
        $('#aa').click(function () {
            if (this.checked){
                $('#aaa :checkbox').prop('checked',true);
            }else {
                $('#aaa :checkbox').prop('checked',false);
            }
        })
    })

        function on() {
            var list = []
            var cid = document.getElementsByName('chee')
            for (var i = 0; i < cid.length; i++) {
                if (cid[i].checked === true) {
                    list.push(cid[i].value)
                }
            }
            console.log(list)
            if (list.length !== 0) {
                $.ajax({
                    url: '{% url 'deleteall' %}',
                    type: 'POST',
                    data: ({
                        'list': list
                    }),
                    traditional: true, //传过来的值是多个的话,与要加这个
                    success: function (date) {
                        location.href = location.href
                    },
                    error: function () {
                        alert('失败')
                    }
                })
            }
        }

</script>
</body>
</html>